package com.weitu.environmental.solidWaste.controller;


import com.weitu.base.controller.BaseController;
import com.weitu.environmental.solidWaste.entity.EntrustDispose;
import com.weitu.environmental.solidWaste.entity.UnitDispose;
import com.weitu.environmental.solidWaste.service.EntrustDisposeService;
import com.weitu.environmental.solidWaste.service.UnitDisposeService;
import com.weitu.paging.DataGridPagination;
import com.weitu.plugin.PageView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhangqingxi 2017-03-31
 */
@Controller
@RequestMapping("environmental/solidWaste/entrustDispose")
public class EntrustDisposeController extends BaseController {

    private final EntrustDisposeService entrustDisposeService;

    @Autowired
    public EntrustDisposeController(EntrustDisposeService entrustDisposeService) {
        this.entrustDisposeService = entrustDisposeService;
    }

    @ResponseBody
    @RequestMapping("/findByParam")
    public Object findByParam(HttpServletRequest request) {


        Map<String, Object> paramMap = new HashMap<String, Object>();

        //获取前台参数
        putParametersIntoMap(paramMap);

        Integer totalNum = entrustDisposeService.findByParamCount(paramMap);//获取总数
        DataGridPagination pagination = DataGridPagination.getInstance(request, totalNum);

        PageView pageView = pagination.getPageView();//生成pageView分页对象
        paramMap.put("pageView", pageView);

        List<EntrustDispose> entrustDisposeList = entrustDisposeService.findByParam(paramMap);

        return pagination.flushDataGridData(entrustDisposeList);
    }

    @ResponseBody
    @RequestMapping("/findAllBySwaId")
    public List<EntrustDispose> findAllBySwaId(String swaId) {
        return entrustDisposeService.findAllBySwaId(swaId);
    }

    @ResponseBody
    @RequestMapping("/findAllByParam")
    public List<EntrustDispose> findAllByParam() {
        Map<String, Object> paramMap = new HashMap<String, Object>();

        //获取前台参数
        putParametersIntoMap(paramMap);
        return entrustDisposeService.findAllByParam(paramMap);
    }


}
